#include "CNetHelper.h"
#if _WIN32
#include <WS2tcpip.h>
#else
#include <arpa/inet.h>
#endif

namespace TB
{
	BOOLN CNetHelper::IpStringToUINT32( CONST_REF(CString) rstrIP, REF(UINT32) rdwIP )
	{
		in_addr addr1;
		if (1 != inet_pton(AF_INET, rstrIP.c_str(), &addr1))
			return false;
		rdwIP = ntohl(addr1.s_addr);
		return true;
	}

	BOOLN CNetHelper::IpUINT32ToString( UINT32 dwIP, REF(CString) rstrIP )
	{
		in_addr addr1;
		addr1.s_addr = htonl(dwIP);
		rstrIP.resize(16);
		rstrIP = inet_ntop(AF_INET, &addr1, rstrIP.data(), rstrIP.size());
		return rstrIP.empty() ? false : true;
	}
}
